<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="创建时间" prop="gmtCreate">
      <el-input v-model="dataForm.gmtCreate" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="gmtModified">
      <el-input v-model="dataForm.gmtModified" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="是否展示，0代表不展示，1代表展示" prop="ifShow">
      <el-input v-model="dataForm.ifShow" placeholder="是否展示，0代表不展示，1代表展示"></el-input>
    </el-form-item>
    <el-form-item label="1代表已删除，0代表未删除" prop="isDeleted">
      <el-input v-model="dataForm.isDeleted" placeholder="1代表已删除，0代表未删除"></el-input>
    </el-form-item>
    <el-form-item label="交易类型（即审核的属于申请/退血/一类的行为）" prop="tradeType">
      <el-input v-model="dataForm.tradeType" placeholder="交易类型（即审核的属于申请/退血/一类的行为）"></el-input>
    </el-form-item>
    <el-form-item label="当前审核节点的id" prop="examineId">
      <el-input v-model="dataForm.examineId" placeholder="当前审核节点的id"></el-input>
    </el-form-item>
    <el-form-item label="交易id，根据id找到全部流程" prop="tradeId">
      <el-input v-model="dataForm.tradeId" placeholder="交易id，根据id找到全部流程"></el-input>
    </el-form-item>
    <el-form-item label="下一个需要审批的节点" prop="nextExamineId">
      <el-input v-model="dataForm.nextExamineId" placeholder="下一个需要审批的节点"></el-input>
    </el-form-item>
    <el-form-item label="需要处理当前节点的人的姓名" prop="operatorName">
      <el-input v-model="dataForm.operatorName" placeholder="需要处理当前节点的人的姓名"></el-input>
    </el-form-item>
    <el-form-item label="需要处理当前节点的人的id" prop="operatorId">
      <el-input v-model="dataForm.operatorId" placeholder="需要处理当前节点的人的id"></el-input>
    </el-form-item>
    <el-form-item label="处理状态(处理状态字典）" prop="operateState">
      <el-input v-model="dataForm.operateState" placeholder="处理状态(处理状态字典）"></el-input>
    </el-form-item>
    <el-form-item label="驳回的原因" prop="backReason">
      <el-input v-model="dataForm.backReason" placeholder="驳回的原因"></el-input>
    </el-form-item>
    <el-form-item label="签字地址" prop="signUrl">
      <el-input v-model="dataForm.signUrl" placeholder="签字地址"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          gmtCreate: '',
          gmtModified: '',
          ifShow: '',
          isDeleted: '',
          tradeType: '',
          examineId: '',
          tradeId: '',
          nextExamineId: '',
          operatorName: '',
          operatorId: '',
          operateState: '',
          backReason: '',
          signUrl: ''
        },
        dataRule: {
          gmtCreate: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          gmtModified: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          ifShow: [
            { required: true, message: '是否展示，0代表不展示，1代表展示不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '1代表已删除，0代表未删除不能为空', trigger: 'blur' }
          ],
          tradeType: [
            { required: true, message: '交易类型（即审核的属于申请/退血/一类的行为）不能为空', trigger: 'blur' }
          ],
          examineId: [
            { required: true, message: '当前审核节点的id不能为空', trigger: 'blur' }
          ],
          tradeId: [
            { required: true, message: '交易id，根据id找到全部流程不能为空', trigger: 'blur' }
          ],
          nextExamineId: [
            { required: true, message: '下一个需要审批的节点不能为空', trigger: 'blur' }
          ],
          operatorName: [
            { required: true, message: '需要处理当前节点的人的姓名不能为空', trigger: 'blur' }
          ],
          operatorId: [
            { required: true, message: '需要处理当前节点的人的id不能为空', trigger: 'blur' }
          ],
          operateState: [
            { required: true, message: '处理状态(处理状态字典）不能为空', trigger: 'blur' }
          ],
          backReason: [
            { required: true, message: '驳回的原因不能为空', trigger: 'blur' }
          ],
          signUrl: [
            { required: true, message: '签字地址不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/examine/operateexamine/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.gmtCreate = data.operateExamine.gmtCreate
                this.dataForm.gmtModified = data.operateExamine.gmtModified
                this.dataForm.ifShow = data.operateExamine.ifShow
                this.dataForm.isDeleted = data.operateExamine.isDeleted
                this.dataForm.tradeType = data.operateExamine.tradeType
                this.dataForm.examineId = data.operateExamine.examineId
                this.dataForm.tradeId = data.operateExamine.tradeId
                this.dataForm.nextExamineId = data.operateExamine.nextExamineId
                this.dataForm.operatorName = data.operateExamine.operatorName
                this.dataForm.operatorId = data.operateExamine.operatorId
                this.dataForm.operateState = data.operateExamine.operateState
                this.dataForm.backReason = data.operateExamine.backReason
                this.dataForm.signUrl = data.operateExamine.signUrl
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/examine/operateexamine/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'gmtCreate': this.dataForm.gmtCreate,
                'gmtModified': this.dataForm.gmtModified,
                'ifShow': this.dataForm.ifShow,
                'isDeleted': this.dataForm.isDeleted,
                'tradeType': this.dataForm.tradeType,
                'examineId': this.dataForm.examineId,
                'tradeId': this.dataForm.tradeId,
                'nextExamineId': this.dataForm.nextExamineId,
                'operatorName': this.dataForm.operatorName,
                'operatorId': this.dataForm.operatorId,
                'operateState': this.dataForm.operateState,
                'backReason': this.dataForm.backReason,
                'signUrl': this.dataForm.signUrl
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
